package com.wanmait.movie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.github.yulichang.wrapper.MPJAbstractLambdaWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.wanmait.movie.entity.Cinema;
import com.wanmait.movie.entity.Food;
import com.wanmait.movie.entity.VO.FoodVO;
import com.wanmait.movie.mapper.CinemaMapper;
import com.wanmait.movie.mapper.FoodMapper;
import com.wanmait.movie.service.FoodService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class FoodServiceImpl extends ServiceImpl<FoodMapper, Food> implements FoodService {
   @Resource
   private FoodMapper foodMapper;
   @Resource
   private CinemaMapper cinemaMapper;

    @Override
    public PageInfo<FoodVO> getFood(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        MPJLambdaWrapper<Food> wrapper = new MPJLambdaWrapper<Food>()
                .selectAll(Food.class)
                .select(Cinema::getCinemaName)
                .leftJoin(Cinema.class,Cinema::getId,Food::getCinemaId);
        return new PageInfo<>(foodMapper.selectJoinList(FoodVO.class,wrapper));

    }
    @Override
    public List<Cinema> getFoods() {
        LambdaQueryWrapper<Cinema> queryWrapper = new LambdaQueryWrapper<Cinema>();
        return cinemaMapper.selectList(queryWrapper);

    }
}
